home *** CD-ROM | disk | FTP | other *** search
Text File | 1990-10-25 | 2.1 KB | 98 lines | [TEXT/MPS ] |
- c
- c Returns the N-th word (space delimited)
- c
- c Function StringWord
- c Takes a string and an integer*4 word number as input.
- c Returns a PASCAL-type string (word n) as result.
- c note: words are separated by whitespace
- c
- c Example provided for owners of Language Systems FORTRAN
- c © 1990 Language Systems Corp.
- c
- c Adapted from a routine in Wild Things.
- c
- string function StringWord(theString,theWordNumber)
-
- C receive the argument by Descriptor
-
- structure /DescRec/
- pointer /character*1/ DataPtr
- integer*2 DataSize
- integer*2 SymT
- end structure
- record /DescRec/ theString
-
- integer*4 chard,strngd
- parameter (chard=18,strngd=19)
-
- integer*4 StringLen,theWordNumber
- integer*4 Word,startC,stopC
- pointer /character*1/ ptr1,ptr2,ptr3
- logical*4 WhiteSpace
-
- C put the address of the characters into a local variable
-
- ptr1 = theString.DataPtr
-
- C store the size of the string
-
- StringLen = MIN(255,ichar(ptr1^))
- ptr1 = ptr1 + 1
-
- c skip any words we don't want
-
- ptr2 = ptr1
- Word = 1
- do while (Word < theWordNumber)
- do while ((WhiteSpace(ptr2)) .and. ((ptr2-ptr1) < StringLen))
- ptr2 = ptr2 + 1
- end do
- do while ((.not. WhiteSpace(ptr2)) .and. ((ptr2-ptr1) < StringLen))
- ptr2 = ptr2 + 1
- end do
- Word = Word + 1
- end do
-
- c skip any white space before desired word
-
- do while ((WhiteSpace(ptr2)) .and. ((ptr2-ptr1) < StringLen))
- ptr2 = ptr2 + 1
- end do
- startC = 1 + (ptr2 - ptr1)
-
- c find the end of the word
-
- ptr3 = ptr2
- do while ((.not. WhiteSpace(ptr3)) .and. ((ptr3-ptr1) < StringLen))
- ptr3 = ptr3 + 1
- end do
- stopC = startC + (ptr3 - ptr2) - 1
- if (stopC < startC) stopC = startC
-
- StringWord = ptr1^(startC:stopC)
-
- return
- end
- c
- c**************************************************c
- c
- c Function WhiteSpace
- c Takes a pointer to a character as input.
- c Returns a logical*4 TRUE if the character
- c is a tab,return or space.
- c
- logical*4 function WhiteSpace(ptr)
-
- pointer /byte/ ptr
-
- select case(ptr^)
- case(9,13,32) !ASCII values of tab, return, space
- WhiteSpace = .true.
- case default
- WhiteSpace = .false.
- end select
- return
- end
- c
- c****************************************c
-